package com.zygk.library.util;

import com.zygk.library.model.M_UserInfo;

/**
 * Created by Wikison on 2018/1/19.
 */
public class UserManager {
  private static UserManager instance;
  M_UserInfo m_UserInfo;

  public static UserManager instance() {
    if (instance == null) {
      instance = new UserManager();
    }
    return instance;
  }

  public M_UserInfo getUserInfo() {
    if (m_UserInfo == null) {
      m_UserInfo = PreferencesHelper.gson.fromJson(
          PreferencesHelper.getSettingString(PreferencesHelper.User.Key.USER_INFO, ""),
          M_UserInfo.class);
    }
    return m_UserInfo;
  }

  /**
   * 存储用户信息
   */
  public void saveUserInfo(M_UserInfo userInfo) {
    PreferencesHelper.setSettingString(PreferencesHelper.User.Key.USER_INFO,
        PreferencesHelper.gson.toJson(userInfo));
    m_UserInfo = userInfo;
  }

  /**
   * 存用户ID
   *
   * @param userID 用户ID
   */
  public void saveUserID(String userID) {
    PreferencesHelper.setSettingString(PreferencesHelper.User.Key.USER_ID, userID);
  }

  /**
   * 取用户ID
   */
  public String getUserID() {
    return PreferencesHelper.getSettingString(PreferencesHelper.User.Key.USER_ID);
  }

  /**
   * 存Token
   *
   * @param token 用户ID
   */
  public void saveToken(String token) {
    PreferencesHelper.setSettingString(PreferencesHelper.User.Key.USER_TOKEN, token);
  }

  /**
   * 取用户ID
   */
  public String getToken() {
    return PreferencesHelper.getSettingString(PreferencesHelper.User.Key.USER_TOKEN, "");
  }
}
